package com.xiaoling.robot;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.xiaoling.robot.bean.DB;
import com.xiaoling.robot.utils.JSONUtils;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 保存数据到 sharedPreferences
        SharedPreferences sp = getSharedPreferences("sharedPreferences", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();

        if(!sp.contains("db")) {
            DB db = new DB();
            db.useTotal = 5;
            db.msgList = new ArrayList<>();
            String json = JSONUtils.objectToJson(db);
            editor.putString("db", json);
            editor.apply();
        }

        Button chatBtn = findViewById(R.id.chat);
        chatBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, ChatActivity.class);
                startActivity(intent);
            }
        });
    }
}
